from django.shortcuts import render,HttpResponse
from .models import *
# Create your views here.
def index(ret):
    return HttpResponse('kkkkkk')

def add_question(request):
    if request.method =='GET':
        return render(request,'add_question.html')
    if request.method == 'POST':
        title = request.POST.get('title')
        qtype = request.POST.get('qtype')
        option1 = request.POST.get('option1')
        option2 = request.POST.get('option2')
        option3 = request.POST.get('option3')
        option4 = request.POST.get('option4')
        ref_answer = request.POST.get('ref_answer')
        analysis = request.POST.get('analysis')
        q1= Question(
            title=title,
            qtype=qtype,
            option1=option1,
            option2=option2,
            option3=option3,
            option4=option4,
            ref_answer=ref_answer,
            analysis=analysis,
        )
        q1.save()
        result = '插入成功'
        return render(request,'add_question.html',{'result':result})

def query_question(request):
    if request.method =='GET':
        question=[]
        return render(request,'query_question.html',{"question":question})
    if request.method == 'POST':
        wd = request.POST.get('wd')
        question=Question.objects.filter(title__contains=wd)
        return render(request,'query_question.html',{"question":question})













